<template>
    <div>
        <van-nav-bar title="标题" style="background-color: black;" />
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="username" name="username" label="手机号" placeholder="手机号"
                    :rules="[{ pattern, message: '请填写用户名' }]" />

                <van-field v-model="result" is-link readonly name="area" label="地区选择" placeholder="点击选择省市区"
                    @click="showArea = true" />
                <van-popup v-model:show="showArea" destroy-on-close position="bottom">
                    <van-area :area-list="areaList" :model-value="pickerValue" @confirm="onConfirm"
                        @cancel="showArea = false" />
                </van-popup>


                <van-field v-model="sms" center clearable label="短信验证码" placeholder="请输入短信验证码">
                    <template #button>
                        <van-button size="small" type="primary" :disabled="time > 0 ? false : true" @click="gosms"> {{ time >
                            0 ? time : '发送验证码' }} </van-button>
                    </template>
                </van-field>
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit"  >
                    登录
                </van-button>
            </div>
        </van-form>

    </div>
</template>

<script setup>
import { ref } from 'vue';
const pattern = /^1[1-9]\d{9}$/
const time = ref(0)
let timer;
const gosms = () => {
   
    timer = setInterval(() => {
        time.value--;
        if (time.value == 0) {
            clearInterval(timer)
        }
    }, 1000);
}
const result = ref('');
const showArea = ref(false);
const pickerValue = ref('');
const username = ref('');
import { useRouter } from 'vue-router';
const router=useRouter()
const onSubmit = (values) => {
    console.log('submit', values);
    router.push('/my')
};

</script>

<style lang="scss" scoped></style>